package com.joysuch.wwyt.core.repository;

import com.joysuch.wwyt.core.entity.BaseConfig;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

public interface BaseConfigDao extends JpaRepository<BaseConfig, Long>, QuerydslPredicateExecutor<BaseConfig> {

    BaseConfig findByTenentIdAndOrgCodeAndCode(Long tenentId, String orgCode, String code);

    BaseConfig findByTenentIdAndOrgCodeAndId(Long tenentId, String orgCode, Long id);

    List<BaseConfig> findByTenentIdAndOrgCodeAndTypeId(Long tenentId, String orgCode, Long typeId);

    BaseConfig findFirstByCode(String code);

    public Page<BaseConfig> findAll(Specification<BaseConfig> spec, Pageable pageable);

    List<BaseConfig> findAllByTenentIdAndOrgCode(Long tenentId, String orgCode);

    List<BaseConfig> findByTypeId(Long id);

    @Query(value = "SELECT * FROM wwyt_base_config WHERE code =?3 AND org_code =?2 AND tenent_id =?1",nativeQuery = true)
    BaseConfig findByTenentIdAndOrgCodeAndCode2(Long tenentId, String orgCode,String code);

    @Query(value = "select * from wwyt_base_config where code = ?1 limit 1",nativeQuery = true)
    BaseConfig findFirstByCodeNative(String code);
}
